package com.lgt.fishmall.member.web;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.lgt.common.utils.R;
import com.lgt.fishmall.member.feign.OrderFeignService;
import com.lgt.fishmall.member.vo.OrderListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
public class MemberWebController {

    @Autowired
    private OrderFeignService orderFeignService;

    @GetMapping(value = "/memberOrder.html")
    public String memberOrderPage(@RequestParam(value = "currPage",defaultValue = "1") Integer pageNum,
                                  Model model, HttpServletRequest request) {

        //获取到支付宝给我们转来的所有请求数据
        //request,验证签名


        //查出当前登录用户的所有订单列表数据
        Map<String,Object> page = new HashMap<>();
        page.put("page",pageNum.toString());


        //远程查询订单服务订单数据

        R orderInfo = orderFeignService.listWithItem(page);
        OrderListVo orderList =  orderInfo.getData("page",new TypeReference<OrderListVo>(){});
        System.out.println(orderList);
        System.out.println(JSON.toJSONString(orderInfo));
        model.addAttribute("orders",orderInfo);
        model.addAttribute("orderpage",orderList);


        return "orderList";
    }


    @RequestMapping(value = "/toApplyOrder")
    public String toApplyOrder (@RequestParam (value = "orderNum") String orderNum){
        System.out.println(orderNum);
        return "redirect:http://order.fishmall.com/pay.html";
    }


}

